home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Language/OS - Multiplatform Resource Library
/
LANGUAGE OS.iso
/
p4
/
p4-1_2b.lha
/
p4-1.2b
/
messages
/
temp.c
< prev
next >
Wrap
C/C++ Source or Header
|
1993-02-06
|
2KB
|
73 lines
#include "p4.h"
extern void slave();
#define MSG_BUFFER 0xfff
#define MSG_LEN_SENT 5
int main(argc,argv)
int argc;
char **argv;
{ p4_initenv(&argc,argv);
if (p4_get_my_id() == 0)
p4_create_procgroup();
slave();
p4_wait_for_end();
}
void slave()
{ int msg_type, msg_len, msg_from;
char *msg_ptr;
int rec_type, rec_len, rec_from;
char *rec_ptr;
int count = 0;
int i, j;
int me = p4_get_my_id();
int total = p4_num_total_slaves();
for(j = 0; j<5000; j++)
{ if (me == 0)
{ msg_ptr = p4_msg_alloc(MSG_BUFFER);
if (msg_ptr == NULL)
{
printf("msg_alloc failed: exiting\n");
exit(99);
}
msg_ptr[0] = 'a';
msg_ptr[1] = 'b';
msg_ptr[2] = 'c';
msg_ptr[3] = 'd';
msg_ptr[4] = '\0';
/*****
printf("msg_ptr: %s\n", msg_ptr);
fflush(stdout);
*****/
msg_len = MSG_LEN_SENT;
msg_type = j;
for(i=0; i<=total; i++)
{ if (i != me) p4_sendb(msg_type, i, msg_ptr, msg_len);
}
p4_msg_free(msg_ptr);
}
else
{ rec_from = -1;
rec_type = -1;
rec_ptr = NULL;
p4_recv(&rec_type, &rec_from, &rec_ptr, &rec_len);
if (me == total && (count++ % 200 == 0))
{ printf("%d received %d bytes from %d: %d count = %d\n",
me, rec_len, rec_from, rec_type, count);
fflush(stdout);
}
p4_msg_free(rec_ptr);
}
}
}